//============================================================================
// Name        : ms013.cpp
// Author      : Tadas
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cmath>
#include <ctime>

#include "lib.h"

using namespace std;

double func(double x, double y, double z) {
	double temp, ats;

	temp = x * x + y * y;
	temp = sqrt(temp);
	temp -= 3;
	temp *= temp;

	ats = z * z + temp;
	return ats;
}

double tank(double z) {
	double ats, temp;

	temp = 5 * z;
	ats = exp(temp);
	return ats;
}

/*
 * temp.cpp
 *
 *  Created on: 2010.06.28
 *      Author: Tadas
 */

int main() {
	seed = time(NULL);

	long i, n1 = 1e6, n, pataike = 0;
	double x, y, z;
	double sw, swx, swy, swz;
	double w, xw, yw, zw;
	double den, vol, volume, denVid;
	double s;

	sw = swx = swy = swz = 0.0;

	vol = 3 * 7 * 4;

	n = 0;

	for (i = 0; i < n1; i++) {
		n++;
		x = 3 * randGe() + 1;
		y = 7 * randGe() - 3;
		z = 4 * randGe() - 2;

		//s = (0.2 * exp(5) - 0.2) * randGe() + 0.2;
		//z = log(5 * s) / 5;
		//den = tank(z);

		den = 1;
		den = exp(5 * z);

		if (func(x, y, z) <= 1) {
			pataike++;
			sw += den;
			denVid += den;
			swx += x * den;
			swy += y * den;
			swz += z * den;
		}
	}

	denVid = denVid / pataike;

	double sant = double(pataike) / double(n);
	volume = sant * vol;

	w = denVid * volume;
	xw = swx / sw;
	yw = swy / sw;
	zw = swz / sw;

	//	printf("\nVidurkis:\n%.3f\t(%.3f ; %.3f ; %.3f)\n", v, vx, vy, vz);
	cout << "Mases c. viso: " << w << " x: " << xw << " y: " << yw << " z: "
			<< zw << endl;
	//	printf("Turis: %.3f\n", volume/12);
	cout << "Turis: " << volume << endl;

	return 0;
}

